package me.shurufa.widget.animutils;

import android.view.View;
import android.view.animation.Animation;
import android.view.animation.Transformation;

/**
 * Create by andy (https://github.com/andyxialm)
 * Create time: 16/5/15 16:10
 * Description :
 */
public class ExpandAnimation extends Animation {
    private final int mStartHeight;
    private final int mDeltaHeight;
    private View view;

    public ExpandAnimation(View v, int startHeight, int endHeight) {
        view = v;
        mStartHeight = startHeight;
        mDeltaHeight = endHeight - startHeight;
    }

    @Override
    protected void applyTransformation(float interpolatedTime, Transformation t) {
        final int newHeight = (int) (mStartHeight + mDeltaHeight * interpolatedTime);
        view.getLayoutParams().height = newHeight;

        if (newHeight <= 0) {
            view.setVisibility(View.GONE);
        } else {
            view.setVisibility(View.VISIBLE);
        }
        view.requestLayout();
    }


    @Override
    public boolean willChangeBounds() {
        return true;
    }
}